package my.example.samplegridview.modal;

import java.util.Vector;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

public class category {
	public static final String Table = "o2s_category";
    public static final Uri    CONTENT_URI = Uri.parse("content://o2s.contentprovider.datacontentprovider/category");
    public static final String SQLCREATE = "CREATE TABLE 'o2s_category' ( " +
    										"'category_id' INT NOT NULL PRIMARY KEY , " +
    										"'image' VARCHAR ( 255 ) , " +
    										"'parent_id' INT , " +
    										"'sort_order' INT , " +
    										"'date_added' DATETIME , " +
    										"'date_modified' DATETIME , " +
    										"'status' INT ) ; ";
    private Context mContext;
    
    private String category_id;
    private String image;
    private String parent_id;
    private String sort_order;
    private String date_added;
    private String date_modified;
    private String status;
    private categorydescription catdescription;
    
    public category(){}
    
    public static Vector<category> SelectCategories(Context mContext){
		Vector<category> categories = new Vector<category>();
		
		Cursor c = mContext.getContentResolver().query(category.CONTENT_URI, null, null,null, null);
		while(c.moveToNext()){
			category cat = new category();
			cat.setCategory_id(c.getString(0));
			cat.setImage(c.getString(1));
			cat.setParent_id(c.getString(2));
			cat.setSort_order(c.getString(3));
			cat.setDate_added(c.getString(4));
			cat.setDate_modified(c.getString(5));
			cat.setStatus(c.getString(6));
			
			categories.add(cat);
		}
		
		return categories;
	}
    
    public category(Context mContext , String category_id){
    	this.mContext = mContext;
    	this.category_id = category_id;
    	catdescription = new categorydescription();
    }
    
	public String getCategory_id() {
		return category_id;
	}
	public void setCategory_id(String category_id) {
		this.category_id = category_id;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public String getParent_id() {
		return parent_id;
	}
	public void setParent_id(String parent_id) {
		this.parent_id = parent_id;
	}
	public String getSort_order() {
		return sort_order;
	}
	public void setSort_order(String sort_order) {
		this.sort_order = sort_order;
	}
	public String getDate_added() {
		return date_added;
	}
	public void setDate_added(String date_added) {
		this.date_added = date_added;
	}
	public String getDate_modified() {
		return date_modified;
	}
	public void setDate_modified(String date_modified) {
		this.date_modified = date_modified;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public categorydescription getCatdescription() {
		String[] arg = {this.category_id};
		Cursor c = mContext.getContentResolver().query(categorydescription.CONTENT_URI, null, "category_id=?", arg, null);
		while(c.moveToNext()){
			catdescription.setCategory_id(this.category_id);
			catdescription.setLanguage_id(String.valueOf(c.getInt(1)));
			catdescription.setName(c.getString(2));
			catdescription.setMeta_keywords(c.getString(3));
			catdescription.setMeta_description(c.getString(4));
			catdescription.setDescription(c.getString(5));
		}
		c.close();
		return catdescription;
	}    
    
}
